#include <iostream>
#include <pthread.h>
#include <unistd.h>
#include <cstdio>
#include <cstring>

__thread int num = 100;

void* routine1(void* args)
{
    int cnt = 5;
    while(cnt--)
    {
        std::cout << "这是线程一, " << "num : " << num << std::endl;
        num += 33;
        sleep(1);
    }
    return nullptr;
}

void* routine2(void* args)
{
    int cnt = 5;
    while(cnt--)
    {
        std::cout << "这是线程二, " << "num : " << num << std::endl;
        sleep(1);
    }
    return nullptr;
}
int main()
{
    pthread_t tid1, tid2;
    // 线程1修改并且打印num
    pthread_create(&tid1, nullptr, routine1, nullptr);
    // 线程2只打印num
    pthread_create(&tid2, nullptr, routine2, nullptr);

    pthread_join(tid1, nullptr);
    pthread_join(tid2, nullptr);

    return 0;
}